import { http } from "@/utils/http";
import type { GetListParamProp, ResultProps } from "@/api/user";

export interface Datum {
  id: number;
  account_id: number;
  business_id: number;
  name: string;
  device_type: string;
  note: string;
  delete_status: number;
  publish_status: number;
  publish_time: Date;
  update_time: Date;
  create_time: Date;
  formula_count: number;
  release_time: null;
  pull_time: null;
}

export interface TreeProp {
  id: number;
  account_id: number;
  business_id: number;
  parent_id: number;
  name: string;
  info: string;
  icon: string;
  type?: string;
  delete_status: number;
  update_time: Date;
  create_time: Date;
  store_list: StoreList[];
  children: ChildProp[];
}

export interface ChildProp {
  id: number;
  account_id: number;
  business_id: number;
  parent_id: number;
  name: string;
  info: null | string;
  icon: null | string;
  delete_status: number;
  update_time: Date;
  create_time: Date;
  store_list: StoreList[];
  children: ChildProp[];
}

export interface StoreList {
  id: number;
  account_id: number;
  business_id: number;
  logo: null | string;
  name: string;
  province: string;
  city: string;
  detail_address: null | string;
  operator: null | string;
  phone: null | string;
  device_num: number;
  device_locknum: number;
  group_id: number;
  store_status: number;
  delete_status: number;
  update_time: Date;
  create_time: Date;
  device_list: DeviceList[];
}

export interface DeviceList {
  id: number;
  account_id: number;
  business_id: number;
  store_id: number;
  device_id: string;
  name: null;
  android_id: null;
  device_model: string;
  device_type: string;
  system_version: null | string;
  brand: null;
  province: string;
  city: string;
  device_status: number;
  run_status: number;
  delete_status: number;
  activation_time: Date;
  update_time: Date;
  create_time: Date;
}

export const formulaVerGetList = (data?: object) => {
  return http.request<ResultProps<Datum[]>>("post", "/formulaVersion/getList", {
    data
  });
};

export const versionsAdd = (data?: object) => {
  return http.request<ResultProps<Datum[]>>("post", "/formulaVersion/add", {
    data
  });
};

export const versionsUpdate = (data?: object) => {
  return http.request<ResultProps<Datum[]>>("post", "/formulaVersion/upd", {
    data
  });
};

export const versionsDelete = (data?: object) => {
  return http.request<ResultProps<Datum[]>>("post", "/formulaVersion/del", {
    data
  });
};

export const updateStatus = (data?: object) => {
  return http.request<ResultProps<Datum[]>>("post", "/formulaVersion/publish", {
    data
  });
};

export const getReleaseSelect = (data?: object) => {
  return http.requestJson<ResultProps<TreeProp[]>>(
    "post",
    "/teaFormula/getReleaseSelect",
    {
      data
    }
  );
};

export interface ReleaseListProp {
  id: number;
  account_id: number;
  business_id: number;
  formula_subid: null;
  version: number;
  group_id: null;
  store_id: null;
  device_id: null | string;
  note: null | string;
  release_time: Date;
}

export const getVersionReleaseList = (data?: object) => {
  return http.request<ResultProps<ReleaseListProp[]>>(
    "post",
    "/teaFormula/getVersionReleaseList",
    {
      data
    }
  );
};

export const addVersions = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/teaFormula/versionRelease", {
    data
  });
};

export interface FormulaListProp {
  id: number;
  accountId: number;
  businessId: number;
  formulaId: string;
  formulaVersion: null;
  version: null;
  formulaSubid: null;
  name: string;
  icon: null;
  deviceType: null;
  note: null;
  deleteStatus: number;
  publishStatus: number;
  releaseStatus: null;
  releaseTime: null;
  publishTime: Date;
  createTime: Date;
  updateTime: Date;
  switchNoCheck: number;
  tagList: null;
  switchTeaOut: "0" | "1";
  timeTeaOut: number;
}

export const getFormulaList = (
  data?: GetListParamProp<{ hxtFormula?: any }>
) => {
  return http.requestJson<ResultProps<FormulaListProp[]>>(
    "post",
    "/teaFormula/getList",
    {
      data
    }
  );
};

export interface FormulaDetailProp {
  hxtFormula: {
    id: number;
    accountId: number;
    businessId: null;
    formulaId: string;
    formulaVersion: null;
    version: number;
    formulaSubid: null;
    name: string;
    icon: null;
    deviceType: string;
    note: null;
    deleteStatus: number;
    publishStatus: number;
    releaseStatus: null;
    releaseTime: null;
    publishTime: Date;
    createTime: Date;
    updateTime: Date;
    switchNoCheck: number;
    tagList: null;
    type: number;
    jbInWater: string | number;
    thirdValue: string;
  };
  hxtFormulaSpecDetailList: HxtFormulaSpecList[];
}

export interface HxtFormulaDetailList {
  id: number;
  specId: string;
  waterValue: string;
  formulaSubid: null;
  temp: string;
  time: string;
  switchStir: string;
  createTime: null;
  updateTime: null;
  deltag: string;
  ice_weight: string;
  fomulaId: string;
  subsectionId: number;
  iceSwitch: string;
  iceWeight: string;
  mixingId: null;
  detail: string;
  switchTeaOut: "0" | "1";
  timeTeaOut: string;
}

export interface HxtFormulaSpecList {
  id: number;
  formulaId: string;
  specId: string;
  specName: string;
  thirdValue: string;
  materialW: string;
  hxtFormulaDetailList: HxtFormulaDetailList[];
}

export const getFormulaDetail = (data?: { formulaId: string }) => {
  return http.requestJson<ResultProps<FormulaDetailProp>>(
    "post",
    "/teaFormula/getDetail",
    {
      data
    }
  );
};

export const addFormula = (data?: object) => {
  return http.requestJson<ResultProps<FormulaListProp>>(
    "post",
    "/teaFormula/add",
    {
      data
    }
  );
};

export const updFormula = (data?: object) => {
  return http.requestJson<ResultProps<FormulaListProp>>(
    "post",
    "/teaFormula/upd",
    {
      data
    }
  );
};

export const updatePublishFormula = (data?: {
  formulaId: string;
  publishStatus: number;
}) => {
  return http.requestJson<ResultProps<null>>(
    "post",
    "/teaFormula/updataPublish",
    {
      data
    }
  );
};

export const delFormula = (data?: { formulaIds: string[] }) => {
  return http.requestJson<ResultProps<null>>("post", "/teaFormula/del", {
    data
  });
};

export const addFormulaList = (data?: object) => {
  return http.requestJson<ResultProps<FormulaListProp>>(
    "post",
    "/teaFormula/addList",
    {
      data
    },
    {
      beforeResponseCallback() {}
    }
  );
};
